<html>
  <head>
    <%= javascript_include_tag :defaults %>
    <%= calendar_date_select_includes "red" %>


    <script type='text/javascript'>


  function set_text(value){
      if(value=="1"){
        document.getElementById("div_s_text").innerHTML = "";
      }else{
        document.getElementById("div_s_text").innerHTML = "s";
      }

   };


  function repeats_select(value){
    document.getElementById("div_repeat_weekly").style.display = 'none';
    document.getElementById("div_repeat1").style.display = '';
    document.getElementById("div_repeat_monthly").style.display = '';
    document.getElementById("div_text").style.display = '';

    switch(value)
    {
      case "No Repeats":
        document.getElementById("div_text").style.display = 'none';
        document.getElementById("div_repeat_monthly").style.display = 'none';
        document.getElementById("div_repeat1").style.display = 'none';
        break;
      case "Daily":
        document.getElementById("div_repeat_weekly").style.display = 'none';
        document.getElementById("div_text").innerHTML = "day";
        break;
      case "Weekly":
        document.getElementById("div_text").innerHTML = "week";
        document.getElementById("div_repeat_weekly").style.display = '';
        break;
      case "Monthly":
        document.getElementById("div_text").innerHTML = "month";
<%#*document.getElementById("div_repeat_weekly").style.visibility = 'visible';%>
        break;
      case "Yearly":
        document.getElementById("div_text").innerHTML = "year";
<%#*document.getElementById("div_repeat_weekly").style.visibility = 'visible';%>
        break;
      default:
<%#*document.getElementById("div_repeat_weekly").style.visibility = 'visible';%>
      }

    };

    function load()
    {
      document.getElementById("repeats").value="No Repeats";
    }
    function sDateOnchage(value){
      document.getElementById("end_date").value=value;
      startDateOnchage();
    }

    function typeOnchage(value){
      if(value=="Holiday"){
 
        document.getElementById("where").readOnly=true;
        document.getElementById("content").readOnly=true;
        document.getElementById("webpage").readOnly=true;


        document.getElementById("where").value="N/A";
        document.getElementById("content").value="N/A";
        document.getElementById("webpage").value="N/A";     

      }else{
        document.getElementById("where").readOnly=false;
        document.getElementById("content").readOnly=false;
        document.getElementById("webpage").readOnly=false;


        document.getElementById("where").value="";
        document.getElementById("content").value="";
        document.getElementById("webpage").value="";
      }


    }

    

    </script>
    <script src="/javascripts/events_calendar_js/calendar_validation.js"></script>

  </head>

  <body onload="load()">

    <h1>New Event</h1>
    <div id="errorText" style="color:red"><%= if(@status=="false") then "Creating event failed !" elsif(@status=="true") then "New Event Added !" else "" end %></div>
    <% form_tag({:action => 'create'} , {:onSubmit => 'return validate();'}) do -%>
      <table cellpadding="4" border="0">
        <tr>
          <td>
            Event Type:
          </td>
          <td>
            <%= select_tag "event_type", options_for_select(@events_type, "Film"),{:onchange => "typeOnchage(this.value)"} %>
          </td>
        </tr>
        <tr>
          <td>
            Title:
          </td>
          <td>
            <%= text_field_tag "title"%>
          </td>
        </tr>
        
        <tr>
          <td>
            Where:
          </td>
          <td>
            <%= text_field_tag "where"%>
          </td>
        </tr>
        <tr>
          <td>
            Description:
          </td>
          <td>
            <%= text_field_tag "content"%>
          </td>
        </tr>

        <tr>
          <td>
            Web Page:
          </td>
          <td colspan="3">
            <%= text_field_tag "webpage"%><span style="font-size:0.8em;color:#C0C0C0">(http://www.samplepage.com)</span>
          </td>
        </tr>


        <tr>

          <td>
            Start Time:
          </td>
          <td>
            <%= calendar_date_select_tag "start_date", Time.now, {:size=>"24%",:time => true ,:onchange => "sDateOnchage(this.value)"}  %>
          </td>

          <td>
            End Time:
          </td>
          <td>
            <%= calendar_date_select_tag "end_date", Time.now, {:size=>"24%",:time => true,:onchange => "onChangeDate()" } %>
          </td>
        </tr>
        <tr>
          <td >
            Repeat :
            </td>
          <td>
            <%= select_tag "repeats", options_for_select(["No Repeats","Daily","Weekly","Monthly","Yearly"], "No Repeats"),{:onchange => 'repeats_select(this.value)'} %>


          </td>
        </tr>
        <tr>
          <td colspan="4" style="background-color:#F0F0F0;" >
            <div id="div_repeat_monthly">
              <% days=[]
              (1..30).each{|i|
                days.push(i.to_s)} %>
              Repeat every:<%= select_tag "repeat_every", options_for_select( days, "1"),{:onchange => "set_text(this.value)"} %> <span id="div_text"></span><span id="div_s_text"></span>

              <hr>
            </div>

            <div id="div_repeat_weekly">
              Repeat On:

              <%= check_box_tag "c_b_sun", true,false%>Sun
              <%= check_box_tag "c_b_mon", true,false%>Mon
              <%= check_box_tag "c_b_tue", true,false%>Tue
              <%= check_box_tag "c_b_wen", true,false%>Wen
              <%= check_box_tag "c_b_thu", true,false%>Thu
              <%= check_box_tag "c_b_fri", true,false%>Fri
              <%= check_box_tag "c_b_sat", true,false%>Sat
              <hr>
            </div>

            <div id="div_repeat1">
              Repeat Until:
              <%= calendar_date_select_tag "repeat_until", Date.today, {:time => false,:onchange => "onChangeUntil()"}%>
            <hr>
            </div>
          </td>

        </tr>
        <tr>
          <td colspan="2">
              Highlight on Calendar: <%= check_box_tag "highlight", true,true%>
          </td>
        </tr>
        <tr>
          <td>
            
            <%= hidden_field_tag 'cal_id', @cal_id %>

          </td>

          <td align="right">
            <br>

            <%= submit_tag 'Save' %>
          </td>
        </tr>

      </table>
    <% end -%>
    <%#= link_to 'Back', posts_path %>
    <script type='text/javascript'>repeats_select("No Repeats") </script>
     <%=link_to 'Back to Events', "/events?title=#{@cal_title}&cal_id=#{@cal_id}" %>
  </body>

</html>







